home *** CD-ROM | disk | FTP | other *** search
/ Teach Your Children: Road Construction Ahead / Teach Your Children: Road Construction Ahead.iso / pc / rca / road.dxr / 00126_simPathHandlers.ls < prev    next >
Encoding:
Text File  |  1996-07-17  |  20.2 KB  |  460 lines

  1. global gSimObject, gTruckObject, gLevelObject
  2.  
  3. on placeBuildings
  4.   set tempPathList to [:]
  5.   set totalBlockList to []
  6.   set cell to the cell of gTruckObject
  7.   if the level of gLevelObject = 1 then
  8.     if the goalCell of gSimObject > 3 then
  9.       set upperCell to getAt([6, 10, 11, 15, 19], random(5))
  10.       set lowerCell to getAt([26, 27, 31, 32, 36, 41], random(6))
  11.     else
  12.       set upperCell to getAt([14, 18, 22, 23, 26, 27], random(6))
  13.       set lowerCell to getAt([28, 33, 37, 38, 42, 46], random(6))
  14.     end if
  15.     set buildingList to pickBuildings(2)
  16.     set buildingList to shuffleList(buildingList)
  17.     placeOneBuilding(lowerCell, the number of cast (getAt(buildingList, 1) & "." & the gridSize of gSimObject))
  18.     placeOneBuilding(upperCell, the number of cast (getAt(buildingList, 2) & "." & the gridSize of gSimObject))
  19.     set segmentDataA to makePathSegment(cell, lowerCell)
  20.     set moveListA to getAt(segmentDataA, 1)
  21.     set blockListA to getAt(segmentDataA, 2)
  22.     set segmentDataB to makePathSegment(cell, upperCell)
  23.     set moveListB to getAt(segmentDataB, 1)
  24.     set blockListB to getAt(segmentDataB, 2)
  25.     if count(moveListA) <= count(moveListB) then
  26.       set tempPathList to appendPathList(tempPathList, moveListA)
  27.       set totalBlockList to appendBlocks(totalBlockList, blockListA)
  28.       disconnectBuildings([upperCell, blockListB])
  29.       set segmentData to makePathSegment(getLast(tempPathList), upperCell)
  30.     else
  31.       set tempPathList to appendPathList(tempPathList, moveListB)
  32.       set totalBlockList to appendBlocks(totalBlockList, blockListB)
  33.       disconnectBuildings([lowerCell, blockListA])
  34.       set segmentData to makePathSegment(getLast(tempPathList), lowerCell)
  35.     end if
  36.     set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1))
  37.     set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2))
  38.     set segmentData to makePathSegment(getLast(tempPathList), the goalCell of gSimObject)
  39.     set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1))
  40.     set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2))
  41.     disconnectBuildings([lowerCell, upperCell, totalBlockList])
  42.   else
  43.     if the level of gLevelObject = 2 then
  44.       if the goalCell of gSimObject > 4 then
  45.         set upperCell to getAt([1, 2, 9, 10, 16, 17, 18, 24, 25, 26, 32, 33, 34, 40, 41, 42, 43, 44, 50, 51, 58], random(20))
  46.         set middleCell to getAt([75, 82, 90, 97, 105, 112, 119, 120, 126, 127, 128, 134, 135], random(13))
  47.         set lowerCell to getAt([76, 77, 78, 79, 84, 85, 86, 87, 91, 92, 93, 94, 99, 100, 101, 102], random(16))
  48.       else
  49.         set upperCell to getAt([7, 8, 14, 15, 21, 22, 23, 28, 29, 30, 35, 36, 37, 40, 41, 42, 43, 44, 48, 49, 56], random(20))
  50.         set middleCell to getAt([69, 77, 84, 92, 99, 107, 114, 115, 121, 122, 123, 129, 130], random(13))
  51.         set lowerCell to getAt([80, 81, 82, 83, 87, 88, 89, 90, 95, 96, 97, 98, 102, 103, 104, 105], random(16))
  52.       end if
  53.       set buildingList to pickBuildings(3)
  54.       set buildingList to shuffleList(buildingList)
  55.       placeOneBuilding(lowerCell, the number of cast (getAt(buildingList, 1) & "." & the gridSize of gSimObject))
  56.       placeOneBuilding(middleCell, the number of cast (getAt(buildingList, 2) & "." & the gridSize of gSimObject))
  57.       placeOneBuilding(upperCell, the number of cast (getAt(buildingList, 3) & "." & the gridSize of gSimObject))
  58.       set segmentDataA to makePathSegment(cell, lowerCell)
  59.       set moveListA to getAt(segmentDataA, 1)
  60.       set blockListA to getAt(segmentDataA, 2)
  61.       set segmentDataB to makePathSegment(cell, middleCell)
  62.       set moveListB to getAt(segmentDataB, 1)
  63.       set blockListB to getAt(segmentDataB, 2)
  64.       if count(moveListA) <= count(moveListB) then
  65.         set tempPathList to appendPathList(tempPathList, moveListA)
  66.         set totalBlockList to appendBlocks(totalBlockList, blockListA)
  67.         disconnectBuildings([middleCell, blockListB])
  68.         set segmentData to makePathSegment(getLast(tempPathList), middleCell)
  69.       else
  70.         set tempPathList to appendPathList(tempPathList, moveListB)
  71.         set totalBlockList to appendBlocks(totalBlockList, blockListB)
  72.         disconnectBuildings([lowerCell, blockListA])
  73.         set segmentData to makePathSegment(getLast(tempPathList), lowerCell)
  74.       end if
  75.       set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1))
  76.       set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2))
  77.       set segmentData to makePathSegment(getLast(tempPathList), upperCell)
  78.       set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1))
  79.       set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2))
  80.       set segmentData to makePathSegment(getLast(tempPathList), the goalCell of gSimObject)
  81.       set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1))
  82.       set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2))
  83.       disconnectBuildings([lowerCell, middleCell, upperCell, totalBlockList])
  84.     else
  85.       if the goalCell of gSimObject > 4 then
  86.         set upperCell to awayFromRiver([9, 10, 17, 18, 25, 26, 33])
  87.         set upmidCell to awayFromRiver([43, 51, 52, 58, 59, 60, 66, 67, 73, 74, 81, 88])
  88.         set lomidCell to awayFromRiver([54, 61, 62, 69, 70, 76, 77, 78, 84, 85, 91, 92, 93, 99, 100, 101])
  89.         set lowerCell to awayFromRiver([105, 112, 113, 119, 120, 126, 127, 128, 134, 135, 142, 143])
  90.       else
  91.         set upperCell to awayFromRiver([14, 15, 21, 22, 28, 29, 36])
  92.         set upmidCell to awayFromRiver([41, 47, 48, 54, 55, 56, 62, 63, 70, 71, 78, 86])
  93.         set lomidCell to awayFromRiver([60, 67, 68, 74, 75, 81, 82, 83, 89, 90, 96, 97, 98, 103, 104, 105])
  94.         set lowerCell to awayFromRiver([99, 106, 107, 114, 115, 121, 122, 123, 129, 130, 136, 137])
  95.       end if
  96.       set buildingList to pickBuildings(4)
  97.       set buildingList to shuffleList(buildingList)
  98.       placeOneBuilding(lowerCell, the number of cast (getAt(buildingList, 1) & "." & the gridSize of gSimObject))
  99.       placeOneBuilding(lomidCell, the number of cast (getAt(buildingList, 2) & "." & the gridSize of gSimObject))
  100.       placeOneBuilding(upmidCell, the number of cast (getAt(buildingList, 3) & "." & the gridSize of gSimObject))
  101.       placeOneBuilding(upperCell, the number of cast (getAt(buildingList, 4) & "." & the gridSize of gSimObject))
  102.       set segmentDataA to makePathSegment(cell, lowerCell)
  103.       set moveListA to getAt(segmentDataA, 1)
  104.       set blockListA to getAt(segmentDataA, 2)
  105.       set segmentDataB to makePathSegment(cell, lomidCell)
  106.       set moveListB to getAt(segmentDataB, 1)
  107.       set blockListB to getAt(segmentDataB, 2)
  108.       if count(moveListA) <= count(moveListB) then
  109.         set tempPathList to appendPathList(tempPathList, moveListA)
  110.         set totalBlockList to appendBlocks(totalBlockList, blockListA)
  111.         disconnectBuildings([lomidCell, blockListB])
  112.         set segmentDataA to makePathSegment(getLast(tempPathList), lomidCell)
  113.         set moveListA to getAt(segmentDataA, 1)
  114.         set blockListA to getAt(segmentDataA, 2)
  115.         set segmentDataB to makePathSegment(getLast(tempPathList), upmidCell)
  116.         set moveListB to getAt(segmentDataB, 1)
  117.         set blockListB to getAt(segmentDataB, 2)
  118.         if count(moveListA) <= count(moveListB) then
  119.           set tempPathList to appendPathList(tempPathList, moveListA)
  120.           set totalBlockList to appendBlocks(totalBlockList, blockListA)
  121.           disconnectBuildings([upmidCell, blockListB])
  122.           set segmentDataA to makePathSegment(getLast(tempPathList), upmidCell)
  123.           set moveListA to getAt(segmentDataA, 1)
  124.           set blockListA to getAt(segmentDataA, 2)
  125.           set segmentDataB to makePathSegment(getLast(tempPathList), upperCell)
  126.           set moveListB to getAt(segmentDataB, 1)
  127.           set blockListB to getAt(segmentDataB, 2)
  128.           if count(moveListA) <= count(moveListB) then
  129.             set tempPathList to appendPathList(tempPathList, moveListA)
  130.             set totalBlockList to appendBlocks(totalBlockList, blockListA)
  131.             disconnectBuildings([upperCell, blockListB])
  132.             set segmentData to makePathSegment(getLast(tempPathList), upperCell)
  133.           else
  134.             set tempPathList to appendPathList(tempPathList, moveListB)
  135.             set totalBlockList to appendBlocks(totalBlockList, blockListB)
  136.             disconnectBuildings([upmidCell, blockListA])
  137.             set segmentData to makePathSegment(getLast(tempPathList), upmidCell)
  138.           end if
  139.           set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1))
  140.           set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2))
  141.         else
  142.           set tempPathList to appendPathList(tempPathList, moveListB)
  143.           set totalBlockList to appendBlocks(totalBlockList, blockListB)
  144.           disconnectBuildings([lomidCell, blockListA])
  145.           set segmentData to makePathSegment(getLast(tempPathList), lomidCell)
  146.           set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1))
  147.           set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2))
  148.           if the connector of getAt(the cellList of gSimObject, upperCell) = 0 then
  149.             set segmentData to makePathSegment(getLast(tempPathList), upperCell)
  150.             set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1))
  151.             set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2))
  152.           end if
  153.         end if
  154.       else
  155.         set tempPathList to appendPathList(tempPathList, moveListB)
  156.         set totalBlockList to appendBlocks(totalBlockList, blockListB)
  157.         disconnectBuildings([lowerCell, blockListA])
  158.         set segmentData to makePathSegment(getLast(tempPathList), lowerCell)
  159.         set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1))
  160.         set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2))
  161.         if the connector of getAt(the cellList of gSimObject, upmidCell) = 0 then
  162.           set segmentData to makePathSegment(getLast(tempPathList), upmidCell)
  163.           set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1))
  164.           set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2))
  165.         end if
  166.         set segmentData to makePathSegment(getLast(tempPathList), upperCell)
  167.         set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1))
  168.         set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2))
  169.       end if
  170.       set segmentData to makePathSegment(getLast(tempPathList), the goalCell of gSimObject)
  171.       set tempPathList to appendPathList(tempPathList, getAt(segmentData, 1))
  172.       set totalBlockList to appendBlocks(totalBlockList, getAt(segmentData, 2))
  173.       disconnectBuildings([lowerCell, lomidCell, upmidCell, upperCell, totalBlockList])
  174.     end if
  175.   end if
  176.   erasePath(tempPathList)
  177.   return tempPathList
  178. end
  179.  
  180. on makePathSegment cell, destCell
  181.   set segmentList to [:]
  182.   set blockList to []
  183.   set tempFinishedFlag to 0
  184.   set cellObject to getAt(the cellList of gSimObject, cell)
  185.   if the level of gLevelObject = 3 then
  186.     set dontCrossRiver to 0
  187.     set destObject to getAt(the cellList of gSimObject, destCell)
  188.     if isCellAboveRiver(cell, cellObject) = isCellAboveRiver(destCell, destObject) then
  189.       set dontCrossRiver to 1
  190.     end if
  191.   end if
  192.   repeat while tempFinishedFlag = 0
  193.     set newMove to 0
  194.     set spriteH to the horizValue of cellObject
  195.     set spriteV to the vertValue of cellObject
  196.     set destH to the horizValue of getAt(the cellList of gSimObject, destCell)
  197.     set destV to the vertValue of getAt(the cellList of gSimObject, destCell)
  198.     set Hdelta to abs(spriteH - destH)
  199.     set Vdelta to abs(spriteV - destV)
  200.     set availableMoveList to availForPath(cell, cellObject, dontCrossRiver)
  201.     if spriteV > destV then
  202.       if spriteH > destH then
  203.         if Hdelta > Vdelta then
  204.           set newMove to tryMove([#w, #NW, #SW, #n, #NE, #E, #s, #SE], availableMoveList)
  205.         else
  206.           set newMove to tryMove([#NW, #n, #w, #NE, #SW, #E, #s, #SE], availableMoveList)
  207.         end if
  208.       else
  209.         if spriteH < destH then
  210.           if Hdelta > Vdelta then
  211.             set newMove to tryMove([#E, #NE, #NW, #n, #SE, #w, #s, #SW], availableMoveList)
  212.           else
  213.             set newMove to tryMove([#NE, #n, #E, #NW, #SE, #w, #s, #SW], availableMoveList)
  214.           end if
  215.         else
  216.           set newMove to tryMove([#n, #NW, #NE, #w, #E, #SW, #SE, #s], availableMoveList)
  217.         end if
  218.       end if
  219.     else
  220.       if spriteV = destV then
  221.         if spriteH > destH then
  222.           set newMove to tryMove([#w, #SW, #NW, #s, #n, #SE, #NE, #E], availableMoveList)
  223.         else
  224.           set newMove to tryMove([#E, #NE, #SE, #n, #s, #NW, #SW, #w], availableMoveList)
  225.         end if
  226.       else
  227.         if spriteH > destH then
  228.           if Hdelta > Vdelta then
  229.             set newMove to tryMove([#w, #SW, #NW, #s, #SE, #n, #E, #NE], availableMoveList)
  230.           else
  231.             set newMove to tryMove([#SW, #s, #w, #NW, #SE, #n, #E, #NE], availableMoveList)
  232.           end if
  233.         else
  234.           if spriteH < destH then
  235.             if Hdelta > Vdelta then
  236.               set newMove to tryMove([#E, #SE, #NE, #s, #SW, #n, #w, #NW], availableMoveList)
  237.             else
  238.               set newMove to tryMove([#SE, #s, #E, #NE, #SW, #n, #w, #NW], availableMoveList)
  239.             end if
  240.           else
  241.             set newMove to tryMove([#s, #SW, #SE, #w, #E, #NW, #NE, #n], availableMoveList)
  242.           end if
  243.         end if
  244.       end if
  245.     end if
  246.     set cell to cell + getProp(the moveList of gSimObject, newMove)
  247.     set cellObject to getAt(the cellList of gSimObject, cell)
  248.     addProp(segmentList, newMove, cell)
  249.     if the tileType of cellObject = #River then
  250.       set dontCrossRiver to 1
  251.       set riverTileName to char 1 of the name of cast the tileNum of cellObject
  252.       set bridgeData to getProp(getProp(the bridgeList of gSimObject, riverTileName), newMove)
  253.       set newMove to getAt(bridgeData, 2)
  254.       set cell to cell + getProp(the moveList of gSimObject, newMove)
  255.       set cellObject to getAt(the cellList of gSimObject, cell)
  256.       addProp(segmentList, newMove, cell)
  257.     end if
  258.     repeat with adjVector in the adjacentList of cellObject
  259.       set adjCell to cell + getProp(the moveList of gSimObject, adjVector)
  260.       set adjObject to getAt(the cellList of gSimObject, adjCell)
  261.       if the tileType of adjObject = #Building then
  262.         set the connector of adjObject to 1
  263.         set newBlocks to blockCrossings(adjCell, adjVector)
  264.         repeat with blockedCell in newBlocks
  265.           add(blockList, blockedCell)
  266.         end repeat
  267.         if adjCell = destCell then
  268.           set tempFinishedFlag to 1
  269.         end if
  270.         exit repeat
  271.       end if
  272.       if adjCell = destCell then
  273.         set tempFinishedFlag to 1
  274.         exit repeat
  275.       end if
  276.     end repeat
  277.   end repeat
  278.   return [segmentList, blockList]
  279. end
  280.  
  281. on availForPath cell, cellObject, dontCrossRiver
  282.   set adjacentCellList to the adjacentList of getAt(the cellList of gSimObject, cell)
  283.   set availableMoveList to []
  284.   repeat with x = 1 to count(adjacentCellList)
  285.     add(availableMoveList, getAt(adjacentCellList, x))
  286.   end repeat
  287.   set filledCellList to []
  288.   repeat with x = 1 to count(availableMoveList)
  289.     set adjVector to getAt(availableMoveList, x)
  290.     set adjCell to cell + getProp(the moveList of gSimObject, adjVector)
  291.     set adjObj to getAt(the cellList of gSimObject, adjCell)
  292.     if (the tileType of adjObj = #Road) or (the tileType of adjObj = #Bridge) or (the tileType of adjObj = #Goal) or (the tileType of adjObj = #Building) then
  293.       add(filledCellList, adjVector)
  294.       next repeat
  295.     end if
  296.     if the tileType of adjObj = #River then
  297.       if (checkBlockForPath(adjCell, adjObj, adjVector) = 1) or (dontCrossRiver = 1) then
  298.         add(filledCellList, adjVector)
  299.       end if
  300.     end if
  301.   end repeat
  302.   repeat with x = 1 to count(filledCellList)
  303.     set filledCell to getAt(filledCellList, x)
  304.     set position to getPos(availableMoveList, filledCell)
  305.     if position <> 0 then
  306.       deleteAt(availableMoveList, position)
  307.     end if
  308.   end repeat
  309.   return availableMoveList
  310. end
  311.  
  312. on checkBlockForPath adjCell, adjObj, adjVector
  313.   set riverTileName to char 1 of the name of cast the tileNum of adjObj
  314.   set bridgeList to getProp(the bridgeList of gSimObject, riverTileName)
  315.   set bridgeData to getProp(bridgeList, adjVector)
  316.   set exitDir to getAt(bridgeData, 2)
  317.   set otherSideCell to adjCell + getProp(the moveList of gSimObject, exitDir)
  318.   set otherSideObj to getAt(the cellList of gSimObject, otherSideCell)
  319.   if getPos(the adjacentList of adjObj, exitDir) = 0 then
  320.     set blockedFlag to 1
  321.   end if
  322.   if (the tileType of otherSideObj = #Road) or (the tileType of otherSideObj = #River) then
  323.     set blockedFlag to 1
  324.   else
  325.     set blockedFlag to 0
  326.   end if
  327.   return blockedFlag
  328. end
  329.  
  330. on erasePath segmentList
  331.   repeat with x = 1 to count(segmentList)
  332.     set cellObj to getAt(the cellList of gSimObject, getAt(segmentList, x))
  333.     set the tileType of cellObj to the startTileType of cellObj
  334.   end repeat
  335. end
  336.  
  337. on fillPath segmentList
  338.   repeat with x = 1 to count(segmentList)
  339.     set cellObj to getAt(the cellList of gSimObject, getAt(segmentList, x))
  340.     if the startTileType of cellObj <> #River then
  341.       set the tileType of cellObj to #Road
  342.       next repeat
  343.     end if
  344.     set the tileType of cellObj to #Bridge
  345.   end repeat
  346. end
  347.  
  348. on placeOneBuilding whichCell, buildingCastnum
  349.   set cellObj to getAt(the cellList of gSimObject, whichCell)
  350.   set the startTileNum of cellObj to buildingCastnum
  351.   set the startTileType of cellObj to #Building
  352.   set the tileNum of cellObj to buildingCastnum
  353.   set the tileType of cellObj to #Building
  354. end
  355.  
  356. on tryMove moveList, availableMoveList
  357.   repeat with vector in moveList
  358.     if getOne(availableMoveList, vector) <> 0 then
  359.       set newMove to vector
  360.       exit repeat
  361.       next repeat
  362.     end if
  363.     set newMove to 0
  364.   end repeat
  365.   return newMove
  366. end
  367.  
  368. on disconnectBuildings buildingDataList
  369.   repeat with x = 1 to count(buildingDataList) - 1
  370.     set cell to getAt(buildingDataList, x)
  371.     set the connector of getAt(the cellList of gSimObject, cell) to 0
  372.   end repeat
  373.   set blockList to getLast(buildingDataList)
  374.   repeat with cell in blockList
  375.     set cellObj to getAt(the cellList of gSimObject, cell)
  376.     initAdjacentList(cellObj)
  377.   end repeat
  378. end
  379.  
  380. on awayFromRiver regionList
  381.   set done to 0
  382.   repeat while done = 0
  383.     set index to random(count(regionList))
  384.     set cell to getAt(regionList, index)
  385.     if byTheRiver(cell) = 1 then
  386.       deleteAt(regionList, index)
  387.       next repeat
  388.     end if
  389.     set done to 1
  390.   end repeat
  391.   return cell
  392. end
  393.  
  394. on byTheRiver cell
  395.   set occupied to 0
  396.   repeat with adjVector in the adjacentList of getAt(the cellList of gSimObject, cell)
  397.     set adjCell to cell + getProp(the moveList of gSimObject, adjVector)
  398.     set occupied to checkForRiver(adjCell)
  399.     if occupied = 1 then
  400.       exit repeat
  401.     end if
  402.   end repeat
  403.   return occupied
  404. end
  405.  
  406. on checkForRiver cell
  407.   set cellObj to getAt(the cellList of gSimObject, cell)
  408.   if the tileType of cellObj = #River then
  409.     set occupied to 1
  410.   else
  411.     set occupied to 0
  412.   end if
  413.   return occupied
  414. end
  415.  
  416. on isCellAboveRiver cell, cellObject
  417.   set vertValue to the vertValue of cellObject
  418.   set vOffset to (the columns of gSimObject * 2) - 1
  419.   set aboveRiverFlag to 0
  420.   set checkCell to cell + vOffset
  421.   repeat while checkCell < count(the cellList of gSimObject)
  422.     set checkObj to getAt(the cellList of gSimObject, checkCell)
  423.     if (the tileType of checkObj = #River) or (the tileType of checkObj = #Bridge) then
  424.       set aboveRiverFlag to 1
  425.       exit repeat
  426.       next repeat
  427.     end if
  428.     set checkCell to checkCell + vOffset
  429.   end repeat
  430.   return aboveRiverFlag
  431. end
  432.  
  433. on appendPathList mainList, addOnList
  434.   fillPath(addOnList)
  435.   repeat with x = 1 to count(addOnList)
  436.     addProp(mainList, getPropAt(addOnList, x), getAt(addOnList, x))
  437.   end repeat
  438.   return mainList
  439. end
  440.  
  441. on appendBlocks totalBlockList, blockList
  442.   repeat with block in blockList
  443.     add(totalBlockList, block)
  444.   end repeat
  445.   return totalBlockList
  446. end
  447.  
  448. on pickBuildings howMany
  449.   set buildingList to []
  450.   repeat with x = 2 to 5
  451.     add(buildingList, getAt(the scenarioData of gSimObject, x))
  452.   end repeat
  453.   set numberToDelete to 4 - howMany
  454.   repeat while numberToDelete > 0
  455.     deleteAt(buildingList, random(count(buildingList)))
  456.     set numberToDelete to numberToDelete - 1
  457.   end repeat
  458.   return buildingList
  459. end
  460.